<template>
  <div style="
        padding: 24px 16px;
        box-sizing: border-box;
        width: 100%;
        position: relative;
      ">
    <el-empty v-if="isShowEmpty" style="height: 100%">
      <el-button type="primary">Button</el-button>
    </el-empty>
    <el-card class="box-card" style="height: 100%">
      <div style="display: flex; flex-direction: column">
        <el-button @click="back()" style="width: 60px">
          <el-icon>
            <ArrowLeftBold/>
          </el-icon>
          返回
        </el-button>
      </div>

      <div>
        <el-divider/>
        <div style="display: flex; flex-direciton: row ;">
          <div style="
                width: 8px;
                height: 20px;
                background-color: darkorange;
                margin-right: 8px;
              "></div>
          <span>学生基本信息</span>
        </div>
        <el-row>
          <el-col
              :key="1"
              :span="12"
              :offset="0">
            <el-card :body-style="{ padding: '10px' }" style="margin:16px 0px">
              <el-row>
                <el-col :span="4">
                  <el-image v-if="student.photoUrl != null" style="width: 160px; height: 200px"
                            :src="`http://127.0.0.1:8090/res/${student.photoUrl}`" fit="cover">
                  </el-image>
                  <el-image v-else-if="student.sex == 1" style="width: 56px; height: 56px"
                            src="/src/assets/boy.png" fit="cover">
                  </el-image>
                  <el-image v-else-if="student.sex == 2" style="width: 56px; height: 56px"
                            src="/src/assets/girl.png" fit="cover">
                  </el-image>
                </el-col>

                <el-col :span="10">
                  <div style="
                  height: 100%;
                  display: flex;
                  flex-direction: column;
                  justify-content: space-around;
                ">
                    <div class="m-10">姓名: {{ student.name }}</div>
                    <div class="m-10">学号: {{ student.stuNo }}</div>
                    <div class="m-10">入学学年: {{ student.year }}</div>
                  </div>
                </el-col>
                <el-col :span="10">
                  <div style="
                  height: 100%;
                  display: flex;
                  flex-direction: column;
                  justify-content: space-around;
                ">
                    <div class="m-10">性别:{{ student.sex == 1 ? "男" : "女" }}</div>
                    <div class="m-10">身份证号: {{ student.cardId }}</div>
                    <div class="m-10">班级: {{ student.className }}</div>
                  </div>
                </el-col>
              </el-row>
            </el-card>
          </el-col>
        </el-row>

        <el-divider/>
        <div style="display: flex; flex-direciton: row">
          <div style="
                width: 8px;
                height: 20px;
                background-color: darkorange;
                margin-right: 8px;
              "></div>
          <span>学生考试信息</span>

          <div style="flex:1"/>
          <el-select @change="changeVal" v-model="semester" class="m-2" placeholder="Select">
            <el-option v-for="item in semesters" :key="item.value" :label="item.label" :value="item.value"/>
          </el-select>

          <el-button @click="printStuExamInfoById" style="margin:0px 16px" type="primary" :icon="Search">
            <el-icon>
              <Printer/>
            </el-icon>
            打印
          </el-button>
        </div>
        <div style="width:100%;height: 500px; display: flex;position: relative;">
          <el-table :data="stuScoreInfo" style="margin-top: 16px;position: absolute;">
            <el-table-column prop="tittle" label="科目" width="100">

            </el-table-column>
            <el-table-column v-for="item in stuExamInfo" :key="item" :label="item.tittle">
              <el-table-column v-for="detail in item.stuExamDetails" :key="detail" :label="detail.tittle" width="100"
                               :prop="detail.key">

              </el-table-column>
            </el-table-column>
            <el-table-column label=" "></el-table-column>
          </el-table>
        </div>

      </div>
    </el-card>
  </div>
</template>


<script>
export default {
  name: "stuInfoPage",
  props: {
    // msg: String
  },
  data() {
    return {
      stuId: null,
      student: {},
      stuExamInfo: null,
      stuScoreInfo: null,
      semester: 1,
      semesters: [
        {
          value: 1,
          label: '七年级上期',
        },
        {
          value: 2,
          label: '七年级下期',
        },
        {
          value: 3,
          label: '八年级上期',
        },
        {
          value: 4,
          label: '八年级下期',
        },
        {
          value: 5,
          label: '九年级上期',
        },
        {
          value: 6,
          label: '九年级下期',
        },
      ]
    };
  },
  mounted() {
    this.stuId = this.$route.query.stuId;
    this.getStuExamInfoById();
  },
  methods: {
    getStuExamInfoById() {
      let that = this;
      this.$http
          .post("/student/getStuExamInfoById"
              , {
                "id": that.stuId, "semester": that.semester
              }
          )
          .then(function (response) {
            that.student = response.data.student;
            that.stuExamInfo = response.data.stuExamInfo.stuExamList;
            that.stuScoreInfo = response.data.stuScoreInfo.stuScoreList;
          })
          .catch(function (error) {
            console.log("error");
          });
    },
    printStuExamInfoById() {
      let that = this;
      this.$http({
        url: "/student/printStuExamInfoById",
        method: 'post',
        data: {
          "id": that.stuId,
          "semester": that.semester
        },
        responseType: 'blob'
      }).then((res) => {
        console.log(res);
        const blob = new Blob([res], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"});
        const elink = document.createElement("a");
        elink.download = `文档.docx`;
        elink.style.display = "none";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href); // 释放URL 对象
        document.body.removeChild(elink);
      });
    },
    back() {
      this.$router.back();
    },
    changeVal(value) {
      this.semester = value;
      this.getStuExamInfoById();
      console.log(value);
    }
  },
};
</script>

<style scoped>
H3,
H4,
span,
p {
  text-align: left;
}

.el-table__header-wrapper {
  background: #f5f7fa;
}

.text-center H4 {
  text-align: center;
}

.text-primary {
  color: #ffb366 !important;
}

.el-col {
  /* border-radius: 4px;
    background-color: rgb(74, 74, 74); */
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
  padding: 8px;
}

.card-body {
  padding: 30px;
  display: flex;
  flex-direction: row;
  border-radius: 4px;
  margin: 8px;
  justify-content: space-around;
}

.text-white {
  color: white;
}

.media .el-icon {
  color: white;
}

h3 {
  padding: 0;
  margin: 0;
}

.configContainer {
  margin: 10px 8px;
  padding: 0px;
  /* border: red 1px solid; */
}

.m-10 {
  margin: 10px 0px
}
</style>
